import axios from "axios";

export default {
  namespaced: true,
  state: {
    //收藏的数量
    num: 0,
    // 收藏列表
    collect: [],
  },
  mutations: {
    queryFavorites(state, value) {
      state.collect = value;
      state.num = value.length;
      console.log(state.collect);
      console.log(state.num, "66666");
    },
  },
  actions: {
    async collectData(context) {
      const res = await axios.get("/api/collect/condition_id", {
        headers: {
          Authorization: "Bearer " + localStorage.getItem("token"),
        },
      });
      // console.log(res.data.datas, "--------");
      //   let cc = [];
      let data = res.data.datas.map(({ goodsID, _id }) => ({
        goodsID,
        _id,
      }));
      context.commit("queryFavorites", data);
    },
  },
};
